package com.fastloan.jn.mgt.all.table.model;

import com.kawins.base.baseabs.BaseModel;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author gelon
 *         createTime 2017/10/29
 */
@javax.persistence.Table(name = "ALL_ROW")
public class AllRow extends BaseModel<String> {


    /**
     * null
     */
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private String id;
    /**
     * 行style
     */
    private String style;
    /**
     * 行数
     */
    private Integer rowNum;
    /**
     * 对应表id
     */
    private String tableId;

    @Transient
    private List<AllCell> allCells ;



    public String getId() {
        return this.id;
    }

    public AllRow setId(String id) {
        this.id = id;
        return this;
    }

    public String getStyle() {
        return this.style;
    }

    public AllRow setStyle(String style) {
        this.style = style;
        return this;
    }

    public Integer getRowNum() {
        return this.rowNum;
    }

    public AllRow setRowNum(Integer rowNum) {
        this.rowNum = rowNum;
        return this;
    }

    public String getTableId() {
        return tableId;
    }

    public AllRow setTableId(String tableId) {
        this.tableId = tableId;
        return this;
    }


    public void addCell(AllCell cell){
        if(allCells == null) { allCells = new ArrayList<>();}
        allCells.add(cell);
    }


    public List<AllCell> getAllCells() {
        if(allCells == null) { allCells = new ArrayList<>();}
        return allCells;
    }

    public AllRow setAllCells(List<AllCell> allCells) {
        this.allCells = allCells;
        return this;
    }

    public void sortSelf() {
        allCells = allCells.stream().sorted(Comparator.comparing(AllCell::getStartColumn)).collect(Collectors.toList());
    }
}
